import React from 'react';
import ProTable from '@ant-design/pro-table';
import { ConfigProvider } from 'antd';

import en_US from 'antd/es/locale-provider/en_US';
import TemplateProTable from '@/components/TemplateProTable';

function CustomizeTemplate(tableProps: any) {
  // 在这里拿到参数过滤
  const filterColumns = () => {
    return (
      tableProps?.columns?.filter(
        (item: any) => !item.hideInSearch && item.valueType !== 'text',
      ) || []
    );
  };

  const filterColumnsText = () => {
    let obj = {};
    (
      tableProps?.columns?.filter(
        (item: any) => !item.hideInSearch && item.valueType === 'text',
      ) || []
    ).forEach((item: any) => {
      obj = {
        ...obj,
        [item.title]: item.dataIndex,
      };
    });
    return obj;
  };

  console.log(filterColumns());

  return (
    <ConfigProvider locale={tableProps.local}>
      <TemplateProTable
        searchParams={{
          columns: filterColumns(),
          labelSelect: filterColumnsText(),
        }}
        {...tableProps}
      />
    </ConfigProvider>
  );
}

export default CustomizeTemplate;
